<?php

namespace app\common\behavior;

use think\Controller;

class Cross extends Controller {

    public function run($dispatch) {
        $hostName = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : "*";
        $headers = [
            'Access-Control-Allow-Origin'      => $hostName,
            'Access-Control-Allow-Credentials' => 'true',
            'Access-Control-Allow-Methods'     => 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
            'Access-Control-Allow-Headers'     => 'x-token, Cache-Control, Content-Disposition, x-requested-with, Host, Sign, Auth-Token, Auth-Identity, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
        ];
        $dispatch->header($headers);
    }
}